package com.bfxy.rocketmq.quickstart;


import com.bfxy.rocketmq.common.Contants;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * 生产者
 * @author 王毅
 */
@Slf4j
public class Producter {


    public static String groupName="test_quick_prodcuer_name";

    /**
     *
     * @param args
     * @throws MQClientException
     * @throws RemotingException
     * @throws InterruptedException
     * @throws MQBrokerException
     */
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer(groupName);
        producer.setNamesrvAddr(Contants.NAMESRV_ADDR);
        producer.setVipChannelEnabled(false);
        producer.start();
        //1、主题  2、标签(消息过滤) 3、用户自定义的key，用来做唯一标识 4、消息体
        for (int i = 0; i < 5; i++) {
            Message message=new Message("test_quick_topic","TagA","KeyA",("hello rocketMQ"+i).getBytes());
            SendResult result = producer.send(message);
            log.info("消息发送的结果是{}",result);
        }
        producer.shutdown();
    }
}
